package server.session.handler;

import server.session.UserSession;
import unit.request.Request;
import unit.request.SearchUserRequest;
import unit.response.Response;
import unit.response.SearchUserRequestResponse;

import java.io.IOException;
import java.util.Map;

/**
 * @author Yuri Denison
 * @since 08.08.11
 */
public class SearchUserRequestHandler implements RequestHandler {
    @Override
    public void handleRequest(Request request, UserSession userSession) {
        SearchUserRequest searchUserRequest = (SearchUserRequest) request;
        Map<String, Integer> searchResult = userSession.getDataStorage().getSearchResult(searchUserRequest.getSearchQuery());
        Response response = new SearchUserRequestResponse(searchUserRequest.getRequestID(), userSession.getSession(), searchResult);
        try {
            userSession.getConnector().send(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
